package com.zhida.smartcontrol.pagectrl;

import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.jay.tools.recycler.MultipleViewHolder;
import com.jay.tools.recycler.SingleRecyclerAdapter;
import com.jay.tools.ui.swipemenu.SwipeMenuLayout;
import com.tan.fonticon.widget.IconTextView;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.pagectrl.ProjectListBean;

import java.util.List;

public class PageCtrlAdapter extends SingleRecyclerAdapter<ProjectListBean> {

    public PageCtrlAdapter(@Nullable List<ProjectListBean> data) {
        super(R.layout.item_page_ctrl, data);
    }

    @Override
    protected void convert(MultipleViewHolder holder, ProjectListBean info) {
        SwipeMenuLayout swipeLayout = holder.getView(R.id.swipe_layout);
        LinearLayout item = holder.getView(R.id.ll_item);
        IconTextView tvArrow = holder.getView(R.id.tv_arrow);
        Button bEdit = holder.getView(R.id.btn_edit);
        Button bDel = holder.getView(R.id.btn_del);
        TextView tvName = holder.getView(R.id.tv_project_name);

        tvName.setText(info.getProjectName());

        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.onClick(info, 0);
                }
            }
        });

        swipeLayout.setOnSwipeExpandListener(new SwipeMenuLayout.ISwipeExpandListener() {
            @Override
            public void isExpand(boolean isExpand) {
                if (isExpand) {
                    tvArrow.setVisibility(View.GONE);
                } else {
                    tvArrow.setVisibility(View.VISIBLE);
                }
            }
        });

        bEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.onClick(info, 1);
                }
            }
        });

        bDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.onClick(info, 2);
                }
            }
        });


    }
}
